package com.mengniu.commerce.admin.controller.system;

import java.util.List;

import com.mengniu.commerce.admin.domain.system.SysStoreSyncConfig;
import com.mengniu.commerce.admin.service.system.ISysStoreSyncConfigService;
import com.mengniu.commerce.common.core.web.controller.BaseController;
import com.mengniu.commerce.common.core.web.domain.AjaxResult;
import com.mengniu.commerce.common.core.web.page.TableDataInfo;
import com.mengniu.commerce.common.log.annotation.Log;
import com.mengniu.commerce.common.log.enums.BusinessType;
import com.mengniu.commerce.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 店铺同步配置Controller
 *
 * @author fanwuZhou
 * @date 2023-11-21
 */
@Controller
@RequestMapping("/admin/config")
public class SysStoreSyncConfigController extends BaseController
{
    private String prefix = "admin/config";

    @Autowired
    private ISysStoreSyncConfigService sysStoreSyncConfigService;

    @RequiresPermissions("admin:config:view")
    @GetMapping()
    public String config()
    {
        return prefix + "/config";
    }

    /**
     * 查询店铺同步配置列表
     */
    @RequiresPermissions("admin:config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysStoreSyncConfig sysStoreSyncConfig)
    {
        startPage();
        List<SysStoreSyncConfig> list = sysStoreSyncConfigService.selectSysStoreSyncConfigList(sysStoreSyncConfig);
        return getDataTable(list);
    }

   /* *//**
     * 导出店铺同步配置列表
     *//*
    @RequiresPermissions("admin:config:export")
    @Log(title = "店铺同步配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysStoreSyncConfig sysStoreSyncConfig)
    {
        List<SysStoreSyncConfig> list = sysStoreSyncConfigService.selectSysStoreSyncConfigList(sysStoreSyncConfig);
        ExcelUtil<SysStoreSyncConfig> util = new ExcelUtil<SysStoreSyncConfig>(SysStoreSyncConfig.class);
        return util.exportExcel(list, "店铺同步配置数据");
    }*/

    /**
     * 新增店铺同步配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存店铺同步配置
     */
    @RequiresPermissions("admin:config:add")
    @Log(title = "店铺同步配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysStoreSyncConfig sysStoreSyncConfig)
    {
        return toAjax(sysStoreSyncConfigService.insertSysStoreSyncConfig(sysStoreSyncConfig));
    }

    /**
     * 修改店铺同步配置
     */
    @RequiresPermissions("admin:config:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysStoreSyncConfig sysStoreSyncConfig = sysStoreSyncConfigService.selectSysStoreSyncConfigById(id);
        mmap.put("sysStoreSyncConfig", sysStoreSyncConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存店铺同步配置
     */
    @RequiresPermissions("admin:config:edit")
    @Log(title = "店铺同步配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysStoreSyncConfig sysStoreSyncConfig)
    {
        return toAjax(sysStoreSyncConfigService.updateSysStoreSyncConfig(sysStoreSyncConfig));
    }

    /**
     * 删除店铺同步配置
     */
    @RequiresPermissions("admin:config:remove")
    @Log(title = "店铺同步配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysStoreSyncConfigService.deleteSysStoreSyncConfigByIds(ids));
    }
}
